package toubiao.utils;


import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import toubiao.domain.po.manage.PoResource;
import utils.UtilCollection;
import utils.UtilString;
import utils.easyui.UtilEzTree;
import utils.easyui.domain.EzTree;

public class ProUtilEasyUiConvert {

	public static List<EzTree> resource2EzTree(PoResource poResource,String pid){
		if(poResource==null){
			return null;
		}
		List<EzTree> EzTreeList=new ArrayList<>();
		EzTree EzTree=new EzTree();
		if(!UtilString.isNullOrEmpty(pid)){
			EzTree.setPid(pid);
		}
		EzTree.setId(poResource.getId()+"");
		EzTree.setText(poResource.getName());
		EzTree.setIconCls(poResource.getIcon());
		EzTree.getAttributes().put("url", poResource.getUrl());
		Set<PoResource> childrenSet=poResource.getChildrenSet();
		if(!UtilCollection.isNullOrEmpty(childrenSet)){
			for(PoResource resource:childrenSet){
				resource2EzTree(resource,poResource.getId()+"");
			}
		}
		EzTreeList.add(EzTree);
		return EzTreeList;
	}
	
	public static List<EzTree> resource2EzTree(List<PoResource> resourceList,String pid){
		if(UtilCollection.isNullOrEmpty(resourceList)){
			return null;
		}

		List<EzTree> easyTreeList=new ArrayList<>();

		for(PoResource poResource:resourceList){
			List<EzTree> subEzTreeList=resource2EzTree(poResource,null);

			easyTreeList.addAll(subEzTreeList);
		}
		UtilEzTree.setTreeLeafStateOpen(easyTreeList);
		return easyTreeList;
	}
}
